function load_doc(url, wd, without_history) {
    NProgress.start();
    $.get(url + "?fr=docaphptop", function (ret) {
        if (ret.status === 1) {
            GV.doc_id = ret.data.id; // 文档ID
            GV.book_id = ret.data.book_id; // 书籍ID
            let title = ret.data.title;
            let book_title = ret.data.book_title;
            $('#book-title').text(book_title);
            $('#book-title').attr('href', $('#book-title').attr('data-href')+'?id='+ ret.data.book_start_id);
            $('.book-ver').text(ret.data.book_ver);
            $("input[name=book_id]").val(GV.book_id); // 设置搜索书籍ID
            $('a.top-btn').each(function() {
                $(this).attr('href', $(this).attr('data-href')+'?id='+ GV.doc_id);
            });
            $("#doc_edit select[name=pid]").val(ret.data.pid);
            $("#doc_edit input[name=id]").val(ret.data.id);
            $("#doc_edit input[name=book_id]").val(ret.data.book_id);
            $("#doc_edit input[name=title]").val(ret.data.title);
            $("#doc_edit input[name=sign]").val(ret.data.sign);
            $("#doc_edit #summary").text(ret.data.summary);
            $("#doc_edit input[name=sort]").val(ret.data.sort);
            $("#doc_edit input[name=ver_int]").val(ret.data.ver_int);
            editor.setMarkdown(ret.data.markdown);
            if (!without_history) {
                history.pushState({}, title, url);
            }
            //切换右侧菜单激活样式
            active_readed_menu(url);
            NProgress.done();
            $('.m-manual .manual-right').animate({scrollTop: 0}, 100);
        } else {
            toast(ret.msg);
            NProgress.done();
        }
    });
}

$(function () {
    // 目录跳转
    $(".article-menu-detail a").click(function (e) {
        e.preventDefault();
        load_doc($(this).attr('href'), '');
    });
    // 搜索结果跳转
    $("#searchList").on("click", "a", function () {
        let id = $(this).attr("data-id");
        let url =  GV.base_href + '?id=' + id;
        let _this = $(this);
        _this.parent("li").siblings().find("a").removeClass("active");
        _this.addClass("active");
        load_doc(url, _this.attr("data-wd"));
    });
    load_doc(GV.base_href + '?id=' + GV.doc_id, '');
});